package middlewares

import (
	"github.com/kataras/iris"

	"im/app"
	"im/app/controller"
	"im/dao"
	"im/errcode"
)

func UserVerifyRongyun(ctx iris.Context) {
	var tokenStr = ctx.URLParamDefault(app.GET_NAME_OF_JWT_TOKEN, ctx.GetHeader(app.GET_NAME_OF_JWT_TOKEN))
	info, err := dao.NewUsersDao().GetInfoByToken(tokenStr)
	if err != nil {
		var base = controller.Base{Ctx:ctx}
		base.SendCry(errcode.NewError(errcode.UnauthorizedOperation))
		return
	}
	ctx.Values().Set("user", info)
	ctx.Next()

}